package cn.iocoder.yudao.module.etl.controller.admin.engine;


import cn.iocoder.yudao.module.etl.dal.dataobject.DeEngine;
import cn.iocoder.yudao.module.etl.dto.KettleDTO;
import cn.iocoder.yudao.module.etl.service.KettleService;
import cn.iocoder.yudao.module.etl.utils.PageUtils;
import cn.iocoder.yudao.module.etl.utils.Pager;
import cn.iocoder.yudao.module.etl.utils.ResultHolder;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

@ApiIgnore
@RequestMapping("/etl/kettle")
@RestController
public class KettleController {

    @Resource
    private KettleService kettleService;

    @ApiOperation("新增/编辑")
    @PostMapping("save")
    public ResultHolder save(@RequestBody DeEngine engine) throws Exception{
        return kettleService.save(engine);
    }

    @ApiIgnore
    @PostMapping("validate")
    public  void validate(@RequestBody KettleDTO kettleDTO) throws Exception{
        kettleService.validate(kettleDTO);
    }

    @ApiOperation("校验")
    @PostMapping("validate/{id}")
    public ResultHolder validate(@PathVariable String id) throws Exception{
        return kettleService.validate(id);
    }

    @ApiOperation("查询")
    @PostMapping("/pageList/{goPage}/{pageSize}")
    public Pager<List<DeEngine>> pageList(@PathVariable int goPage, @PathVariable int pageSize) {
//        Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
        Page<Object> page = new Page<>(goPage,pageSize);
        return PageUtils.setPageInfo(page, kettleService.pageList());
    }

    @ApiOperation("删除")
    @DeleteMapping("delete/{id}")
    public void delete(@PathVariable String id) throws Exception{
        kettleService.delete(id);
    }
}
